# 初始字典
person_info = {
    "name": "Alex",
    "age": 30,
    "country": "USA",
    "language": ["English", "Spanish"],
    "is_student": False
}

# 1. 打印 name 值
print("1. 姓名:", person_info["name"])

# 2. 修改 age 为 31
person_info["age"] = 31
print("2. 修改后的年龄:", person_info["age"])

# 3. 添加新键值对 height: 175
person_info["height"] = 175
#print("3. 添加身高后的字典:", person_info)

# 4. 删除 is_student 键
person_info.pop("is_student")
#print("4. 删除 is_student 后的字典:", person_info)

# 5. 遍历并打印所有键值对
print("5. 所有键值对:")
for key, value in person_info.items():
    print(f"  {key}: {value}")

# 6. 检查并添加 email
if "email" not in person_info:
    person_info["email"] = "alex@example.com"
#print("6. 添加 email 后的字典:", person_info)

# 7. 将 language 改为只包含 "English"
person_info["language"] = ["English"]
#print("7. 修改后的语言列表:", person_info["language"])

# 8. 打印 language 列表的长度
print("8. 语言列表长度:", len(person_info["language"]))

# 9. 向 language 列表添加 "French"
person_info["language"].append("French")
#print("9. 添加 French 后的语言列表:", person_info["language"])

# 10. 循环插入 hobby1~hobby3
for i in range(1, 4):
    key = f"hobby{i}"
    value = f"hobby{i}"
    person_info[key] = value
print("10. 添加爱好后的字典:", person_info)
####################################################################################
#进阶：
employees = {
    101: {
        "name": "Alice",
        "age": 30,
        "gender": "Female",
        "position": "Data Scientist",
        "team": "Research",
        "salary_history": [70000, 80000, 90000]
    },
    102: {
        "name": "Bob",
        "age": 24,
        "gender": "Male",
        "position": "Developer",
        "team": "Engineering",
        "salary_history": [65000, 75000]
    }
}

# 1. 新增员工信息
employees[103] = {
    "name": "Charlie",
    "age": 28,
    "gender": "Male",
    "position": "Analyst",
    "team": "Business",
    "salary_history": [60000]
}

# 2. 删除指定员工
employees.pop(102, None)  # 删除ID102的员工，不存在则忽略

# 3. 更新员工101的年龄
employees[101]["age"] = 31

# 4. 增加员工101的最新薪资
employees[101]["salary_history"].append(95000)

# 5. 计算员工101的平均薪资
avg = sum(employees[101]["salary_history"]) / len(employees[101]["salary_history"])
#print("5. 员工101的平均薪资:", avg_salary)

# 6. 找出所有年龄>25岁的员工
senior = {emp_id: emp["name"] for emp_id, emp in employees.items() if emp["age"] > 25}
print("6. 年龄>25的员工:", senior)

# 7. 为每个员工添加 bonus 键（最新薪资的10%）
for emp in employees.values():
    emp["bonus"] = emp["salary_history"][-1] * 0.1

# 8. 更新员工101的职位
employees[101]["position"] = "Senior Data Scientist"

# 9. 移除所有员工的 gender 键
for emp in employees.values():
    emp.pop("gender", None)

# 10. 创建仅包含 name 和 position 的新字典
name_position = {emp_id: {"name": emp["name"], "position": emp["position"]} 
                     for emp_id, emp in employees.items()}
print("10. 仅包含姓名和职位的字典:", name_position)

# 打印最终的 employees 字典
print("\n最终的员工信息字典:")
for emp_id, emp_info in employees.items():
    print(f"员工ID {emp_id}: {emp_info}")